 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModaLabel">
  	<form class="form-horizontal">
  	     <input type="hidden"   name="commissionRule.id" id="commissionRuleId">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		     <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModaLabel">${_res["commission.rule.associatedObject"]}</h4>
		      </div>
		     <div class="modal-body">
					<div class="partentDivWrap">
						<div class="content_wrap">
							<div class="zTreeDemoBackground left">
								<ul id="role_tree" class="ztree"></ul>
							</div>
						</div>          
					</div>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-warning" data-dismiss="modal">${_res["system.return"]}</button>
		        <button type="button" class="btn btn-primary" onClick="submitPrivilege();">${_res["system.confirm"]}</button>
		      	<input type="hidden" id="hiddenurl">
		      </div>
		    </div>
		  </div>
	 </form>
</div>

<script src="${cxt!}/js/platform/tree.js"></script>
<script>
	$(document).ready(function(){
		initTreeData();
	});
	
	var treeObj;// 树对象   
	var treeNodes;// 树节点，
	var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		view: {
			showIcon: false
		}
	};
	
	
	/* zhengshikang  树形checkboxTree加载  */
	function initTreeData() {
		$('#myModal').on('show.bs.modal', function(event) {
			var button = $(event.relatedTarget); // Button that triggered the modal
			var params = new Array();
			var whatever = button.data('whatever'); // Extract info from data-* attributes
			params = whatever.split(",");
			$("#commissionRuleId").val(params[0]);
			$("#hiddenurl").val(params[2]);
			var commissionRuleName = button.parents("tr").find("td").eq(0).text();
			var modal = $(this);
			modal.find('.modal-title').text(commissionRuleName + ': 关联对象 ');
			var url = cxt + params[1] + "/" + params[0];
			$.ajax({
				url : url,
				type : "get",
				dataType : "json",
				contentType:"application/json",
				success : function(data) {
					treeNodes = data.treeNodes;
					treeObj = $.fn.zTree.init($("#role_tree"), setting, treeNodes);
				}
			});
			
			
		})
	}
	
	
	/* 提交角色 分配的权限 */
	function submitPrivilege(){
		var resourceIds = getCheckedValues();
		var para = "commissionRuleId=" + $("#commissionRuleId").val(); 
		var data = {ruleid:$("#commissionRuleId").val(),selectIds:resourceIds};
		var hiddenurl = $("#hiddenurl").val();
		url = "${cxt!}"+hiddenurl;
		$.ajax({
			url : encodeURI(encodeURI(url)),
			type : "post",
			dataType : "json",
			data : data,
			success : function(data) {
				if(data.result){
					$("#myModal").modal('hide');
					alert("权限分配成功");
				}
			}
		});	
		return true;
	}
	
	//获得选中的权限
	function getCheckedValues() {
		var values = "";
		for ( var i = 0, j = treeNodes.length; i < j; i++) {
			var nodes = treeObj.getNodeByParam("id", treeNodes[i].id,null);
			console.log("==="+JSON.stringify(nodes)+"----");
			if (nodes.checked == true) {
				if (values == "") {
					values = nodes.id;
				} else {
					values = values + "," + nodes.id;
				}
			}
		}
		console.log("***********"+values+"***********");
		var valuesIds = encodeURI(values);
		return valuesIds;
	}
</script>
 